From 8ab3685a396a617c712d6ee3acb4d54976339c4b Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Sat, 12 Aug 2023 17:02:59 -0400 Subject: android: Adjust setup fragment layout Fixes padding issues in small and large layouts and allows viewpager to reach into system insets. --- .../org/yuzu/yuzu_emu/fragments/SetupFragment.kt | 29 +++++++--- .../src/main/res/layout-w600dp/fragment_setup.xml | 60 +++++++++++---------- .../app/src/main/res/layout/fragment_setup.xml | 62 ++++++++++++---------- 3 files changed, 88 insertions(+), 63 deletions(-) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/SetupFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/SetupFragment.kt index 8ca768dcf..e00013c1b 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/SetupFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/SetupFragment.kt @@ -19,6 +19,7 @@ import androidx.core.content.ContextCompat import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat import androidx.core.view.isVisible +import androidx.core.view.updatePadding import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.navigation.findNavController @@ -351,15 +352,29 @@ class SetupFragment : Fragment() { private fun setInsets() = ViewCompat.setOnApplyWindowInsetsListener( binding.root - ) { view: View, windowInsets: WindowInsetsCompat -> + ) { _: View, windowInsets: WindowInsetsCompat -> val barInsets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) val cutoutInsets = windowInsets.getInsets(WindowInsetsCompat.Type.displayCutout()) - view.setPadding( - barInsets.left + cutoutInsets.left, - barInsets.top + cutoutInsets.top, - barInsets.right + cutoutInsets.right, - barInsets.bottom + cutoutInsets.bottom - ) + + val leftPadding = barInsets.left + cutoutInsets.left + val topPadding = barInsets.top + cutoutInsets.top + val rightPadding = barInsets.right + cutoutInsets.right + val bottomPadding = barInsets.bottom + cutoutInsets.bottom + + if (resources.getBoolean(R.bool.small_layout)) { + binding.viewPager2 + .updatePadding(left = leftPadding, top = topPadding, right = rightPadding) + binding.constraintButtons + .updatePadding(left = leftPadding, right = rightPadding, bottom = bottomPadding) + } else { + binding.viewPager2.updatePadding(top = topPadding, bottom = bottomPadding) + binding.constraintButtons + .updatePadding( + left = leftPadding, + right = rightPadding, + bottom = bottomPadding + ) + } windowInsets } } diff --git a/src/android/app/src/main/res/layout-w600dp/fragment_setup.xml b/src/android/app/src/main/res/layout-w600dp/fragment_setup.xml index cbe631d88..406df9eab 100644 --- a/src/android/app/src/main/res/layout-w600dp/fragment_setup.xml +++ b/src/android/app/src/main/res/layout-w600dp/fragment_setup.xml @@ -1,5 +1,5 @@ - + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_alignParentTop="true" + android:layout_alignParentBottom="true" + android:clipToPadding="false" /> - + android:layout_alignParentBottom="true" + android:layout_margin="8dp"> - + + + + + - + diff --git a/src/android/app/src/main/res/layout/fragment_setup.xml b/src/android/app/src/main/res/layout/fragment_setup.xml index d7bafaea2..9499f6463 100644 --- a/src/android/app/src/main/res/layout/fragment_setup.xml +++ b/src/android/app/src/main/res/layout/fragment_setup.xml @@ -1,5 +1,5 @@ - - - + android:layout_above="@+id/constraint_buttons" + android:layout_alignParentTop="true" + android:clipToPadding="false" /> - + android:layout_margin="8dp" + android:layout_alignParentBottom="true"> + + + + + + - + -- cgit v1.2.3